using Audio;
using Consts;
using Dto;
using Newtonsoft.Json;
using UI;

namespace Net.Handler
{
    public class ChatHandler : HandlerBase
    {
        public override void OnReceive(ResBase resBase)
        {
            switch (resBase.subCode)
            {
                case ChatCodeConst.DEFAULT:
                {
                    ChatDto chatDto = JsonConvert.DeserializeObject<ChatDto>(resBase.result.ToString());
                    string userId = chatDto.userId;
                    int chatType = chatDto.chatType;
                    string text = chatDto.text;
                    // 显示文字
                    Dispatch(AreaCode.UI, UIEvent.PLAYER_CHAT, chatDto);
                    // 播放声音
                    Dispatch(AreaCode.AUDIO, AudioEvent.PLAY_EFFECT_AUDIO, "Chat_" + chatType);
                    break;
                }
            }
        }
    }
}